<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Contents extends CH_Controller{

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	 /**
         * Constructor
         */
	function __construct() { 
		parent::__construct(); 
		$this->init();
		$this->load->helper(array('form','array', 'url','common','directory'));
		$this->load->model(array('contents_model','menu_model'));
    } 

	
	/*
	@컨텐츠 관리	
	*/
	function contentsForm(){
		$this->load->library('databasei');
		$this->load->library('tree');
	
		$url =$this->uri_church();
		if($this->input->post('dbjob')){
			$msg='';
			switch($this->input->post('dbjob')){
				case('i'): //컨텐츠(파일) 등록
					$msg='등록 되었습니다.';
					$this->contents_model->create();
				break;
				case('u'): //컨텐츠(파일) 수정
					$msg='수정 되었습니다.';
					$this->contents_model->update();
				break;
				case('d'): //컨텐츠(파일) 삭제
					$msg='삭제 되었습니다.';
					$this->contents_model->delete();
				break;
			}
			
			$rtn_link='';
			switch($this->input->post('page_type')){
				case('HTML'):
					$rtn_link = 'contents/contentsForm/contents_html';
				break;
				case('BOARD'):
					$rtn_link = 'contents/contentsForm/contents_board';
				break;
				case('GALLERY'):
					$rtn_link = 'contents/contentsForm/contents_gallery';
				break;
				case('PLUGIN'):
					$rtn_link = 'contents/contentsForm/contents_plugin';
					break;
				default:
					$rtn_link = 'contents/contentsForm/contents_html';
				break;
			}

			$this->alert->jalert($msg, base_url($rtn_link."/id/".$this->input->post('id')));
			exit;
		}
			
		$id = ($this->uri->segment(5)) ? $this->uri->segment(5) : $this->input->post('id');
	
		$this->load->library('Xmlparser');
		$data = array(
				'_title' => '컨텐츠관리',
				'_group' => 'homepage',
				'_content' => $url,
				'id'=> $id
		);
				
		$data = array_merge($data, $this->contents_model->select($id));

		return $data;
		
	}
	
	
	/**
	 * 메뉴 생성
	 *
	 * @access	public
	 * @return	void
	 */
	function menu(){
		$this->menu_model->create();
		exit;
	}
}

/* End of file html.php */
/* Location: ./application/controllers/contents.php */